﻿namespace Web.Control.WWW.Group
{

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
    using Model.WWW_WWW.Group;
    using System.Collections.Generic;

    /// <summary>
    /// EditGroup 的摘要说明
    /// </summary>
    public class EditGroup : BaseControl
    {
        /// <summary>
        /// 组信息
        /// </summary>
        protected GroupModel gm;
        /// <summary>
        /// tag列表
        /// </summary>
        protected List<string> tagList;
        protected string gid;
        protected override void OnLoad(EventArgs e)
        {
            string memberno = HttpContext.Current.User.Identity.Name;            
            if (memberno == "")
            {
                Response.Redirect(LoginHost + "/User/login.htm?ReturnUrl=" + Page.Request.Url.AbsoluteUri.Split('?')[0]);                
            }
            if (!string.IsNullOrEmpty(Request["gid"]))
            {
                gid = Request["gid"];
                ArrayList arrList = BLF.WWW_WWW.Group.Group.GetGroupInfo(gid, memberno);
                if (arrList == null || arrList.Count < 2)
                {
                    Response.End();
                    return;
                }
                gm = arrList[0] as GroupModel;
                if (string.IsNullOrEmpty(gm.Title))
                {
                    Response.End();
                    return;
                }
                tagList = arrList[1] as List<string>;
            }
            else
            {
                Response.End();
                return;
            }
            base.OnLoad(e);
        }
        /// <summary>
        /// 检查是否选择该tag
        /// </summary>
        /// <param name="tag">tag</param>
        /// <returns>bool</returns>
        protected bool TagCheck(string tag)
        {
            for (int i = tagList.Count - 1; i >= 0; i--)
            {
                if (tag == tagList[i])
                {
                    tagList.Remove(tag);
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 取出剩余tag
        /// </summary>
        /// <returns></returns>
        protected string Tags()
        {
            string tag = "";
            for (int i = tagList.Count - 1; i >= 0; i--)
            {
                tag += tagList[i] + " ";
            }
            return tag;
        }
    }
}
